#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
pthread_t ntid; //线程号

void printids(const char *s)
{
    pid_t pid;     //进程标识符
    pthread_t tid; //线程标识符
    pid = getpid();
    tid = pthread_self();                                                                         //分别获得进程和线程编号
    printf("%s pid %u tid %u (0x%x)\n", (unsigned int)pid, (unsigned int)tid, (unsigned int)tid); //打印线程和进程编号
}

//线程中开始运行的函数
void *thr_fn(void *agr)
{
    printids("new thread: ");
    return ((void *)0);
}
//主函数
int main(void)
{
    int err;
    err = pthread_create(&ntid, NULL, thr_fn, NULL); //创建一个线程
    if (err != 0)
    {
        printf("can't create thread: %s\n", strerror(err));
    }
    printids("main thread:"); //打印主线程号；
    sleep(1);
    exit(0);
}
//这是调试结果：
// (gdb) run
// Starting program: /home/richard/LinuxTest/myPthread/pthread_create
// [Thread debugging using libthread_db enabled]
// Using host libthread_db library "/lib64/libthread_db.so.1".
// [New Thread 0x7ffff77f1700 (LWP 62561)]

// Program received signal SIGSEGV, Segmentation fault.
// 0x00007ffff783eef9 in vfprintf () from /lib64/libc.so.6
// Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7.x86_64
// (gdb) backtrace
// #0  0x00007ffff783eef9 in vfprintf () from /lib64/libc.so.6
// #1  0x00007ffff7845329 in printf () from /lib64/libc.so.6
// #2  0x000000000040074a in printids (s=0x4008af "main thread:") at pthread_create.c:13
// #3  0x00000000004007bd in main () at pthread_create.c:31
//还是找不出问题所在
